home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1320 / 1320.xpi / chrome / gmanager.jar / content / overlayToolbarMenu.js < prev    next >
Text File  |  2010-01-22  |  9KB  |  223 lines

  1. // Gmail Manager
  2. // By Todd Long <longfocus@gmail.com>
  3. // http://www.longfocus.com/firefox/gmanager/
  4.  
  5. var gmanager_ToolbarMenu = new function()
  6. {
  7.   this.__proto__ = new gmanager_BundlePrefix("gmanager-toolbar-menu-");
  8.   
  9.   this.init = function()
  10.   {
  11.     // Load the accounts manager
  12.     this._manager = Components.classes["@longfocus.com/gmanager/manager;1"].getService(Components.interfaces.gmIManager);
  13.   }
  14.   
  15.   this._createMenuitem = function(aLabel)
  16.   {
  17.     var menuitem = document.createElement("menuitem");
  18.     menuitem.setAttribute("label", this.getString(aLabel));
  19.     menuitem.setAttribute("accesskey", this.getString(aLabel + "-ak"));
  20.     return menuitem;
  21.   }
  22.   
  23.   this.buildMenu = function(aPopup)
  24.   {
  25.     var accounts = this._manager.getAccounts({});
  26.     var menuitem = null;
  27.     
  28.     // Clear the menu
  29.     gmanager_Utils.clearKids(aPopup);
  30.     
  31.     // Compose Mail
  32.     var composeMenu = document.createElement("menu");
  33.     var composeMenupopup = document.createElement("menupopup");
  34.     composeMenu.setAttribute("label", this.getString("compose-mail"));
  35.     composeMenu.setAttribute("accesskey", this.getString("compose-mail-ak"));
  36.     composeMenupopup.setAttribute("onpopupshowing", "event.stopPropagation(); return gmanager_ToolbarMenu.buildComposeMenu(this);");
  37.     composeMenu.appendChild(composeMenupopup);
  38.     aPopup.appendChild(composeMenu);
  39.     
  40.     // Separator
  41.     aPopup.appendChild(document.createElement("menuseparator"));
  42.     
  43.     // Check if any accounts exist
  44.     if (accounts.length > 0)
  45.     {
  46.       var toolbarPanel = aPopup.parentNode;
  47.       var numLoggedIn = 0;
  48.       
  49.       for (var i = 0; i < accounts.length; i++)
  50.         numLoggedIn += (accounts[i].loggedIn ? 1 : 0);
  51.       
  52.       // Login All Accounts
  53.       menuitem = this._createMenuitem("login-all-accounts");
  54.       menuitem.setAttribute("oncommand", "gmanager_Accounts.loginAllAccounts();");
  55.       menuitem.setAttribute("disabled", (numLoggedIn == accounts.length));
  56.       aPopup.appendChild(menuitem);
  57.       
  58.       // Logout All Accounts
  59.       menuitem = this._createMenuitem("logout-all-accounts");
  60.       menuitem.setAttribute("oncommand", "gmanager_Accounts.logoutAllAccounts();");
  61.       menuitem.setAttribute("disabled", (numLoggedIn == 0));
  62.       aPopup.appendChild(menuitem);
  63.       
  64.       // Check All Accounts
  65.       menuitem = this._createMenuitem("check-all-accounts");
  66.       menuitem.setAttribute("oncommand", "gmanager_Accounts.checkAllAccounts();");
  67.       menuitem.setAttribute("disabled", (numLoggedIn == 0));
  68.       aPopup.appendChild(menuitem);
  69.       
  70.       // Separator
  71.       aPopup.appendChild(document.createElement("menuseparator"));
  72.       
  73.       if (gmanager_Utils.isAccountToolbar(toolbarPanel))
  74.       {
  75.         var panelAccount = toolbarPanel.account;
  76.         var displayAccount = toolbarPanel.displayAccount;
  77.         
  78.         if (displayAccount)
  79.         {
  80.           if (displayAccount.loggedIn)
  81.           {
  82.             // Logout Selected Account
  83.             menuitem = this._createMenuitem("logout-selected-account");
  84.             menuitem.setAttribute("oncommand", "gmanager_Accounts.logoutAccount('" + displayAccount.email + "');");
  85.             aPopup.appendChild(menuitem);
  86.           }
  87.           else
  88.           {
  89.             // Login Selected Account
  90.             menuitem = this._createMenuitem("login-selected-account");
  91.             menuitem.setAttribute("oncommand", "gmanager_Accounts.loginAccount('" + displayAccount.email + "');");
  92.             aPopup.appendChild(menuitem);
  93.           }
  94.           
  95.           // Check Selected Account
  96.           menuitem = this._createMenuitem("check-selected-account");
  97.           menuitem.setAttribute("oncommand", "gmanager_Accounts.checkAccount('" + displayAccount.email + "');");
  98.           menuitem.setAttribute("disabled", !displayAccount.loggedIn);
  99.           aPopup.appendChild(menuitem);
  100.           
  101.           // Display Mail Snippets...
  102.           menuitem = this._createMenuitem("display-snippets");
  103.           menuitem.setAttribute("oncommand", "gmanager_Alerts.display('" + displayAccount.email + "');");
  104.           menuitem.setAttribute("disabled", (!displayAccount.loggedIn && displayAccount.getSnippets({}).length == 0));
  105.           aPopup.appendChild(menuitem);
  106.           
  107.           // Separator
  108.           aPopup.appendChild(document.createElement("menuseparator"));
  109.         }
  110.         
  111.         for (var i = 0; i < accounts.length; i++)
  112.         {
  113.           var account = accounts[i];
  114.           var email = account.email;
  115.           var unread = account.unread;
  116.           
  117.           menuitem = document.createElement("menuitem");
  118.           menuitem.setAttribute("class", "gmanager-toolbar-menuitem");
  119.           menuitem.setAttribute("checked", (displayAccount && displayAccount.email == email));
  120.           menuitem.setAttribute("default", (panelAccount && panelAccount.email == email));
  121.           menuitem.setAttribute("alias", gmanager_Utils.toUnicode(account.alias));
  122.           menuitem.setAttribute("unread", unread);
  123.           menuitem.setAttribute("icontype", account.type);
  124.           menuitem.setAttribute("status", gmanager_Utils.toStyleStatus(account.status));
  125.           menuitem.setAttribute("newMail", unread > 0);
  126.           menuitem.setAttribute("oncommand", "gmanager_ToolbarMenu.switchAccount('" + email + "');");
  127.           
  128.           aPopup.appendChild(menuitem);
  129.         }
  130.         
  131.         // Separator
  132.         aPopup.appendChild(document.createElement("menuseparator"));
  133.       }
  134.     }
  135.     else
  136.     {
  137.       // Login Account...
  138.       menuitem = this._createMenuitem("login-account");
  139.       menuitem.setAttribute("oncommand", "window.openDialog('chrome://gmanager/content/login/login.xul', 'login', 'centerscreen,chrome,modal');");
  140.       aPopup.appendChild(menuitem);
  141.       
  142.       // Separator
  143.       aPopup.appendChild(document.createElement("menuseparator"));
  144.     }
  145.     
  146.     // Visit Homepage
  147.     menuitem = this._createMenuitem("visit-homepage");
  148.     menuitem.setAttribute("oncommand", "gmanager_Utils.loadSimpleURI(gmanager_Utils.WEBSITE);");
  149.     aPopup.appendChild(menuitem);
  150.     
  151.     // Options...
  152.     menuitem = this._createMenuitem("options");
  153.     menuitem.setAttribute("default", "true");
  154.     menuitem.setAttribute("oncommand", "window.openDialog('chrome://gmanager/content/options/options.xul', 'options', 'centerscreen,chrome,modal,resizable');");
  155.     aPopup.appendChild(menuitem);
  156.     
  157.     // Show the menu
  158.     return true;
  159.   }
  160.   
  161.   this.buildComposeMenu = function(aPopup)
  162.   {
  163.     var accounts = this._manager.getAccounts({});
  164.     var menuitem = null;
  165.     
  166.     // Clear the menu
  167.     gmanager_Utils.clearKids(aPopup);
  168.     
  169.     // Default Mail Client
  170.     menuitem = this._createMenuitem("default-client");
  171.     menuitem.setAttribute("oncommand", "gmanager_ToolbarMenu.composeAccount(null);");
  172.     aPopup.appendChild(menuitem);
  173.     
  174.     if (accounts && accounts.length > 0)
  175.     {
  176.       // Separator
  177.       aPopup.appendChild(document.createElement("menuseparator"));
  178.       
  179.       for (var i = 0; i < accounts.length; i++)
  180.       { 
  181.         var email = accounts[i].email;
  182.         menuitem = document.createElement("menuitem");
  183.         menuitem.setAttribute("label", email);
  184.         menuitem.setAttribute("oncommand", "gmanager_ToolbarMenu.composeAccount('" + email + "');");
  185.         aPopup.appendChild(menuitem);
  186.       }
  187.     }
  188.     
  189.     // Show the menu
  190.     return true;
  191.   }
  192.   
  193.   this.composeAccount = function(aEmail)
  194.   {
  195.     var location = this._manager.global.getCharPref("compose-tab-location");
  196.     var href = gmanager_Utils.getHref(document.popupNode);
  197.     
  198.     gmanager_Accounts.loadCompose(aEmail, location, href);
  199.   }
  200.   
  201.   this.switchAccount = function(aEmail)
  202.   {
  203.     var account = this._manager.getAccount(aEmail);
  204.     
  205.     if (account)
  206.     {
  207.       var toolbarPanel = document.popupNode;
  208.       
  209.       if (gmanager_Utils.isAccountToolbar(toolbarPanel))
  210.         toolbarPanel.displayAccount = account;
  211.       
  212.       if (toolbarPanel.getAttribute("id") == "gmanager-toolbar-panel")
  213.         gmanager_Prefs.setCharPref("current", account.email);
  214.       
  215.       if (account.loggedIn && this._manager.global.getBoolPref("toolbar-auto-check"))
  216.         account.check();
  217.       else if (!account.loggedIn && this._manager.global.getBoolPref("toolbar-auto-login"))
  218.         account.login(null);
  219.     }
  220.   }
  221.   
  222.   this.init();
  223. }